using System;
using NUnit.Framework;
using ValidationFramework.Reflection;

namespace ValidationFramework.Tests.Reflection
{

	public class ParameterDescriptorTest
	{

		[TestFixture]
		public class Constructor
		{

			[Test]
			public void InstanceMethod()
			{
				const string methodName = "InstanceMethod";
				var handle = typeof(ParameterDescriptorTest).GetMethod(methodName).MethodHandle;
				var methodDescriptor = new MethodDescriptor(handle);

				const string parameterName = "param1";
				var parameterDescriptor = methodDescriptor.Parameters[parameterName];
				Assert.AreEqual(parameterName, parameterDescriptor.Name);
				Assert.AreEqual(methodDescriptor, parameterDescriptor.Method);
				Assert.AreEqual(0, parameterDescriptor.Position);
				Assert.AreEqual(1, parameterDescriptor.Rules.Count);
				Assert.AreEqual(parameterDescriptor, parameterDescriptor.Rules.InfoDescriptor);

				Assert.AreEqual(methodDescriptor.Parameters.MethodDescriptor, methodDescriptor);

			}


			[Test]
			public void StaticMethod()
			{
				const string methodName = "StaticMethod";
				var handle = typeof(ParameterDescriptorTest).GetMethod(methodName).MethodHandle;
				var methodDescriptor = new MethodDescriptor(handle);

				const string parameterName = "param1";
				var parameterDescriptor = methodDescriptor.Parameters[parameterName];
				Assert.AreEqual(parameterName, parameterDescriptor.Name);
				Assert.AreEqual(methodDescriptor, parameterDescriptor.Method);
				Assert.AreEqual(0, parameterDescriptor.Position);
				Assert.AreEqual(1, parameterDescriptor.Rules.Count);
				Assert.AreEqual(parameterDescriptor, parameterDescriptor.Rules.InfoDescriptor);


				Assert.AreEqual(methodDescriptor.Parameters.MethodDescriptor, methodDescriptor);
			}

		}
		[TestFixture]
		public class GetValue
		{

			[Test]
			[ExpectedException(typeof(NotImplementedException))]
			public void Exception()
			{
				const string methodName = "StaticMethod";
				var handle = typeof(ParameterDescriptorTest).GetMethod(methodName).MethodHandle;
				var methodDescriptor = new MethodDescriptor(handle);

				const string parameterName = "param1";
				var parameterDescriptor = methodDescriptor.Parameters[parameterName];
				parameterDescriptor.GetValue(null);
			}

		}
		public void InstanceMethod([RequiredIntRule]int param1)
		{

		}



		public static void StaticMethod([RequiredIntRule]int param1)
		{

		}
	}
}